<template>
  <div class="home">
    <van-nav-bar
      :title="deviceInfo.devicename"
      left-arrow
      @click-left="onClickLeft"
      @click-right="onClickRight"
    >
      <template #right>
        <van-icon name="info" size="22" />
      </template>
    </van-nav-bar>
    <iframe src="https://easysmart.live" class="home-frame" scrolling="yes">
      <p>Your browser does not support iframes.</p>
    </iframe>
  </div>
</template>

<script>
import { Toast } from "vant";
import * as echarts from "echarts";
var send = {};
export default {
  name: "custom_page_index",
  components: {},
  created: function () {},
  mounted: function () {
    this.initInterface();
    setTimeout(() => {
      this.myEcharts();
    }, 10);
  },
  data: function () {
    return {
      paramsRes: {},
      deviceInfo: {},
      charts: [],
      tableData: [],
      iData: [],
      cresData: [],
      camera: "",
    };
  },
  watch: {
    cresData: {
      handler(newVal, oldVal) {
        console.log(newVal);
        for (let i = 0; i < newVal.length; i++) {
          console.log(newVal[i]);
          this.chart[i].setOption({
            xAxis: {
              data: newVal[i].date,
            },
            series: [
              {
                data: newVal[i].data,
              },
            ],
          });
        }
      },
      deep: true,
    },
  },

  activated: function () {
    // 在 keepAlive 被激活的时候，调用指定加载页面组件的方法
    console.log("indexkeepalive");
    console.log(this.paramsRes);
    //this.myEcharts();
    this.camera = JSON.parse(localStorage.getItem(this.deviceInfo.id));
    if (this.camera === null) {
      this.camera = {
        cameraState: false,
        cameraIP: "",
      };
      localStorage.setItem(this.deviceInfo.id, JSON.stringify(this.camera));
    }
  },
  methods: {

    initInterface() {
      this.paramsRes = this.$route.params;
      this.iData = this.paramsRes.resData;
      this.cresData = this.paramsRes.cData;
      this.deviceInfo = this.paramsRes.deviceInfo;
      var id = this.deviceInfo.id;
      this.camera = JSON.parse(localStorage.getItem(id));
      console.log(this.camera);
    },

    onClickLeft() {
      this.$router.back(-1);
    },
    onClickRight() {
      this.$router.push({
        name: "interface_page_info",
        params: {
          // resData: this.paramsRes.resData,
          // cData: this.paramsRes.cData,
          deviceInfo: this.paramsRes.deviceInfo,
          routerType: "push",
        },
      });
    },
  },
};
</script>

<style lang="scss" scoped>
.home {
  width: 100%;
  height: 100%;
  overflow: auto;
  display: flex;
  flex-flow: column;
  position: absolute;
  &-frame {
    height: 100%;
  }
}

</style>
